var intersection = function(nums1, nums2) {
    let shortArr1 = nums1.length >= nums2.length ? nums2 : nums1;
    let longArr = nums1.length >= nums2.length ? nums1 : nums2;
    let result = [];

    //先将短数组去重
    let shortArr = [...new Set(shortArr1)]
    console.log(shortArr)
    //再在长数组中遍历
    for(let i = 0;i < shortArr.length;i++){
        console.log(longArr.indexOf(shortArr[i]))
        if(longArr.indexOf(shortArr[i]) >= 0){
            result.push(shortArr[i])
        }
    }
    return result
};

let result = intersection([2,6,2,9,1],[7,1])
console.log(result)
